package com.sander.guardmanagement.ui.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sander.guardmanagement.R;
import com.sander.guardmanagement.until.AppUnit;
import com.sander.guardmanagement.until.UserInfoManager;

public class AppSettingActivity extends AppCompatActivity {


    public Button siginoutbutton ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_app_setting);
        initCallBack();
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

        initView();

    }
    private void initCallBack(){
        FrameLayout frameLayout = (FrameLayout) findViewById(R.id.callbackLayout);
        frameLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        this.getUserInfo();
    }

    public void initView(){


        RelativeLayout layout1 = (RelativeLayout)findViewById(R.id.peopleinforelativelayout);
        layout1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d("sander","on click people info");
                Intent intent = new Intent(AppSettingActivity.this,SDPersonalInformationActivity.class);
                startActivity(intent);
            }
        });

        RelativeLayout layout2 = (RelativeLayout)findViewById(R.id.changepassworldlativelayout);
        layout2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d("sander","on click change passworld");
                Intent intent = new Intent(AppSettingActivity.this,RegisteredActivity.class);
                Bundle bundle = new Bundle();
                bundle.putBoolean("ischange",true);
                intent.putExtras(bundle);
                startActivity(intent);

            }
        });

        RelativeLayout layout3 = (RelativeLayout)findViewById(R.id.callbaclinforelativelayout);
        layout3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d("sander","on click call back");

                Intent intent = new Intent(AppSettingActivity.this,FeedbackActivity.class);
                startActivity(intent);
            }
        });

        TextView textView = (TextView)findViewById(R.id.versiontextview);
        String info = textView.getText().toString();
        textView.setText(info + ": " + AppUnit.getVersionCode(getApplicationContext()));


        siginoutbutton = (Button) findViewById(R.id.siginoutbutton);
        siginoutbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent  = new Intent(AppSettingActivity.this,IntroductionGuradActivity.class);

                startActivity(intent);
                UserInfoManager.sharedManager().userInfo = null;
                UserInfoManager.sharedManager().saveUserInfo(null,null,getApplicationContext());

            }
        });
    }

    public void getUserInfo(){
        TextView textView = (TextView)findViewById(R.id.account_people);
        String phone = UserInfoManager.sharedManager().getUserInfo().phone;
        textView.setText(phone);

    }

}
